package com.bbzn.device.client.utils;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

/**
 * @Author wulongbo
 * @Date 2021/9/23 15:30
 * @Version 1.0
 */

@Slf4j
public class CwtingProductUtils {

    /**
     * 设备类型：烟感：YG，底座+烟感：DZ，气感 ：QG，消防手报按钮：XS，防火门检测：XM，温感：WG，电气检测：DQ ，喷淋：PL，门磁：MC，警号：JH，
     * 紧急按钮：SO，红外：HW，水浸：LS，电源监测：PW，电机：DJ，电动车检测：DC
     */
    private static String[] prefix = {"YG", "DZ", "QG", "XS", "XM", "WG", "DQ", "PL", "MC", "JH", "SO", "HW", "LS", "PW", "DJ", "DC"};//去掉字符串前缀为YG、DZ

    /**
     * 去掉字符串指定的前缀
     *
     * @param str    字符串名称
     * @param prefix 前缀数组
     * @return
     */
    public static String removePrefix(String str) {
        if (StringUtils.isEmpty(str)) {
            return "";
        } else {
            String[] prefixArray = prefix;
            for (int i = 0; i < prefix.length; ++i) {
                String pf = prefixArray[i];
                if (str.toLowerCase().matches("^" + pf.toLowerCase() + ".*")) {
                    return str.substring(pf.length());//截取前缀后面的字符串
                }
            }
            return str;
        }
    }

}
